<template>
  <div>
    <van-swipe :autoplay="3000" lazy-render>
      <van-swipe-item v-for="(banner, index) in state.bannerList" :key="index">
        <img :src="banner.pic" />
      </van-swipe-item>
    </van-swipe>
  </div>
</template>

<script>
import { onMounted, reactive } from 'vue';
import { reqBannerList } from '@/api/requests/home.js'
export default {
  name: 'TopNav',
  setup() {
    const state = reactive({
      bannerList: [],
    })

    onMounted(async () => {
      let result = await reqBannerList()
      state.bannerList = result.data.banners
    });

    return { state };
  },
}
</script>

<style lang="less" scoped>
/deep/ // 深度样式
.van-swipe {
  box-sizing: border-box;
  width: 100%;

  .van-swipe__track {
    .van-swipe-item {
      display: flex;
      justify-content: center;
      align-items: center;

      img {
        border-radius: .2rem;
        width: 95%;
        height: 3rem;
      }
    }
  }

  .van-swipe__indicator--active {
    background-color: rgb(52, 215, 155);
  }
}
</style>